// ActionScript file
package com.maccman.activeresource.models
{
	import com.maccman.activeresource.ActiveResource

	import mx.rpc.IResponder;
	import com.maccman.aireo.model.AireoModelLocator;
	import flash.events.Event;
	import com.maccman.net.SocketURLLoader;
	import com.herrodius.AppSettings;
	import mx.controls.Alert;
	
	
	
	public class Session extends ActiveResource {
		
		private static var model:AireoModelLocator = AireoModelLocator.getInstance();
		private static var settings : AppSettings = AppSettings.getInstance();
		
		public function Session(responder:IResponder) {
			super(model.appUrl,"session",responder);
		}
		
		public function login(user:String, pass:String):void {
			var o:Object = new Object;
			o.login = user;
			o.password = pass;
			o.guid = model.guid;
			o.version = model.version;
			super.connection(loginResultHandler, POST, o, null);
		}
		
		private function loginResultHandler(event:Event):void {
			var loc:String = SocketURLLoader(event.target).responseHeaders['Location'];
			var num:String = (loc.split('/').pop()).toString();
			super._responder.result(num);
		}
		
		public function logout():void {
			super.connection(logoutResultHander, DELETE, null, null, null);
		}
		
		private function logoutResultHander(event:Event):void {
			super._responder.result(event.target);
		}

	}
}